package com.psm.controller;

import com.google.common.collect.Lists;
import com.jfinal.aop.Before;
import com.jfinal.ext.render.excel.PoiRender;
import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.render.JsonRender;
import com.jfinal.upload.UploadFile;
import com.psm.interceptor.IndexInterceptor;
import com.psm.model.*;
import com.psm.util.Base64Util;
import com.psm.util.IdcardValidator;
import com.psm.util.ImgUtil;
import com.psm.util.PoiExt;
import com.psm.util.StrUtil;

import org.apache.log4j.Logger;
import sun.misc.BASE64Decoder;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * Created by cheam on 15/6/19.
 */
@Before(IndexInterceptor.class)
public class StudentController extends BaseController<SysDepartment> {
    public Logger log=Logger.getLogger(getClass());

    public void index(){
        render("index.html");
    }


    public void listJson(){

        Record user = getCurrentUser();

        List<Object> param = new ArrayList<Object>();
        StringBuffer where = new StringBuffer();
        /** 添加查询字段条件*/
        String sortName = this.getPara("sort");
        String sortOrder = this.getPara("order", "desc");

        String student_name = this.getPara("student_name", "");
        String student_id_cart = this.getPara("student_id_cart", "");

        String dep_id = this.getPara("dep_id", "");
        String type = this.getPara("type", "");

        where.append(" and FIND_IN_SET(s.dep_id,getDepChildList("+user.get("dep")+"))");

        if(type.equals("1") && !"".equals(dep_id)){
            where.append(" and FIND_IN_SET(s.dep_id,getDepChildList("+dep_id+"))");
        }else if(type.equals("2") && !"".equals(dep_id)){
            where.append(" and s.class_id="+dep_id);
        }

        if(!"".equals(student_name)){
            where.append(" and s.student_name like '%"+student_name+"%'");
        }
        if(!"".equals(student_id_cart)){
            where.append(" and s.student_id_cart like '%"+student_id_cart+"%'");
        }

        if(SysRole.me.is_teacher(getCurrentUserId().toString())){
            where.append(" and exists (select 1 from bk_class bc where bc.id=s.class_id and bc.teacher_id="+getCurrentUserId()+") ");
        }

        if (sortName != null) {
            where.append(" order by ");
            where.append(sortName);
            where.append(" ");
            where.append(sortOrder);
        }

        String sql1 = "select s.*," +
                "bk_class.class_name bk_class_name," +
                "student_sex.name student_sex_name," +
                "student_hk_type.name student_hk_type_name, " +
                "student_hj_address.name student_hj_address_name, " +
                "student_is_marray.name student_is_marray_name," +
                "student_type.name student_type_name," +
                "app_user_type.name app_user_type_name," +
                "national_rank.name national_rank_name," +
                "up_national_rank.name up_national_rank_name," +
                "is_not_testing_theory.name is_not_testing_theory_name," +
                "student_cultural.name student_cultural_name," +
                "student_nationality.name student_nationality_name," +
                "student_political.name student_political_name," +
                "student_duty_rank.name student_duty_rank_name";
        String sql2 = "from bk_student s " +
                "left join bk_class bk_class on s.class_id=bk_class.id " +
                "left join sys_pa_code student_sex on s.student_sex=student_sex.id " +
                "left join sys_pa_code student_hj_address on s.student_hj_address=student_hj_address.id " +
                "left join sys_pa_code student_hk_type on s.student_hk_type=student_hk_type.id " +
                "left join sys_pa_code student_is_marray on s.student_is_marray=student_is_marray.id " +
                "left join sys_pa_code student_type on s.student_type=student_type.id " +
                "left join sys_pa_code app_user_type on s.app_user_type=app_user_type.id " +
                "left join sys_pa_code national_rank on s.national_rank=national_rank.id " +
                "left join sys_pa_code up_national_rank on s.up_national_rank=up_national_rank.id " +
                "left join sys_pa_code is_not_testing_theory on s.is_not_testing_theory=is_not_testing_theory.id " +
                "left join sys_pa_code student_cultural on s.student_cultural=student_cultural.id " +
                "left join sys_pa_code student_nationality on s.student_nationality=student_nationality.id " +
                "left join sys_pa_code student_political on s.student_political=student_political.id " +
                "left join sys_pa_code student_duty_rank on s.student_duty_rank=student_duty_rank.id " +
                " where 1=1 "+where.toString();

        Page<Record> p = Db.paginate(this.getParaToInt("page", 1), this.getParaToInt("rows", 20),sql1,sql2,param.toArray());
        DataGrid dg = new DataGrid();
        dg.setRows(p.getList());
        dg.setTotal(p.getTotalRow());

        renderJson(dg);
    }

    public void add_project_student(){
         this.setAttr("class_id",getPara("class_id"));
         this.setAttr("project_id",getPara("project_id"));

        render("add_project_student.html");
    }

    public void load_add_student_list_json(){

        Record user = getCurrentUser();

        List<Object> param = new ArrayList<Object>();
        StringBuffer where = new StringBuffer();
        /** 添加查询字段条件*/
        String sortName = this.getPara("sort");
        String sortOrder = this.getPara("order", "desc");

        String class_id = this.getPara("class_id", "");
        String project_id = this.getPara("project_id", "");

        where.append(" and s.class_id="+class_id);
        where.append(" and not exists (select 1 from bk_project_student s where s.project_id="+project_id+" and s.class_id="+class_id+" and s.student_id) ");

        if (sortName != null) {
            where.append(" order by ");
            where.append(sortName);
            where.append(" ");
            where.append(sortOrder);
        }

        String sql1 = "select s.*," +
                "bk_class.class_name bk_class_name," +
                "student_sex.name student_sex_name," +
                "student_hk_type.name student_hk_type_name, " +
                "student_is_marray.name student_is_marray_name," +
                "student_type.name student_type_name," +
                "app_user_type.name app_user_type_name," +
                "national_rank.name national_rank_name," +
                "up_national_rank.name up_national_rank_name," +
                "is_not_testing_theory.name is_not_testing_theory_name," +
                "student_cultural.name student_cultural_name," +
                "student_nationality.name student_nationality_name," +
                "student_political.name student_political_name," +
                "student_duty_rank.name student_duty_rank_name";
        String sql2 = "from bk_student s " +
                "left join bk_class bk_class on s.class_id=bk_class.id " +
                "left join sys_pa_code student_sex on s.student_sex=student_sex.id " +
                "left join sys_pa_code student_hk_type on s.student_hk_type=student_hk_type.id " +
                "left join sys_pa_code student_is_marray on s.student_is_marray=student_is_marray.id " +
                "left join sys_pa_code student_type on s.student_type=student_type.id " +
                "left join sys_pa_code app_user_type on s.app_user_type=app_user_type.id " +
                "left join sys_pa_code national_rank on s.national_rank=national_rank.id " +
                "left join sys_pa_code up_national_rank on s.up_national_rank=up_national_rank.id " +
                "left join sys_pa_code is_not_testing_theory on s.is_not_testing_theory=is_not_testing_theory.id " +
                "left join sys_pa_code student_cultural on s.student_cultural=student_cultural.id " +
                "left join sys_pa_code student_nationality on s.student_nationality=student_nationality.id " +
                "left join sys_pa_code student_political on s.student_political=student_political.id " +
                "left join sys_pa_code student_duty_rank on s.student_duty_rank=student_duty_rank.id " +
                " where 1=1 "+where.toString();

        Page<Record> p = Db.paginate(this.getParaToInt("page", 1), this.getParaToInt("rows", 20),sql1,sql2,param.toArray());
        DataGrid dg = new DataGrid();
        dg.setRows(p.getList());
        dg.setTotal(p.getTotalRow());

        renderJson(dg);
    }





   

    public void import_student(){
        render("import_student.html");
    }
    public void importphoto(){
        render("importphoto.html");
    }

    public void impdata_student_info() {

        String seq_id = System.currentTimeMillis()+"";

        UploadFile uf = getFile("file_name", seq_id);

        String dep_id = getPara("dep_id");
        String class_id = getPara("class_id");

        Map<String, Object> map = PoiExt.ReadExcel(uf.getSaveDirectory() + "/" + uf.getFileName(),"student", "insert into bk_project_student_import_temp (seq_id,c_1,c_2,c_3,c_4,c_5,c_6,c_7,c_8,c_9,c_10,c_11,c_12,c_13,c_14,c_15,c_16,c_17,c_18,c_19,c_20,c_21,c_22,c_23,c_24,c_25,c_26,c_27,c_28,c_29,c_30) VALUES (" + seq_id + ",?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", 30);

        //去掉身份证为空的
        Db.update("delete from bk_project_student_import_temp  where c_4 is null and seq_id=?",seq_id);

        Record str_has_id_cart_has = Db.findFirst("select GROUP_CONCAT(t.c_4) student_id_cart from bk_project_student_import_temp t where t.seq_id=? group by t.c_4 having count(1)>1 ",seq_id);
        Record str_has_sb_cart_has = Db.findFirst("select GROUP_CONCAT(t.c_2) student_sb_cart from bk_project_student_import_temp t where t.seq_id=? group by t.c_2 having count(1)>1 ",seq_id);

        Record str_has_id_cart = Db.findFirst("select GROUP_CONCAT(t.c_4) student_id_cart from bk_project_student_import_temp t,bk_student s where s.student_id_cart=t.c_4 and t.seq_id=?",seq_id);
        Record str_has_sb_cart = Db.findFirst("select GROUP_CONCAT(t.c_2) student_sb_cart from bk_project_student_import_temp t,bk_student s where s.student_sb_cart=t.c_2 and t.seq_id=?",seq_id);


        if(null!= str_has_id_cart_has.get("student_id_cart") && !str_has_id_cart.get("student_id_cart").toString().equals("")){
            rendJson_(0,"请检查模板，模板中身份证号重复："+str_has_id_cart.get("student_id_cart"));
            return;
        }
        if(null!= str_has_sb_cart_has.get("student_id_cart") && !str_has_id_cart.get("student_id_cart").toString().equals("")){
            rendJson_(0,"请检查模板，模板中社保卡号重复："+str_has_id_cart.get("student_id_cart"));
            return;
        }

        if(null!= str_has_id_cart.get("student_id_cart") && !str_has_id_cart.get("student_id_cart").toString().equals("")){
            rendJson_(0,"身份证已存在："+str_has_id_cart.get("student_id_cart"));
            return;
        }
        if(null!= str_has_sb_cart.get("student_sb_cart") && !str_has_sb_cart.get("student_sb_cart").toString().equals("")){
            rendJson_(0,"社保卡已存在："+str_has_sb_cart.get("student_sb_cart"));
            return;
        }

        String sql = "insert into bk_student (dep_id,class_id,student_name,student_sb_cart,student_sb_ffd,student_id_cart,student_sex,student_birthday,student_hj_address,student_hj_address_detail,student_hk_type,student_is_marray,student_nationality,student_political,at_company,student_type,app_user_type,national_rank,up_national_rank,is_not_testing_theory,student_cultural,student_high_school_record,student_title,student_duty,student_age_limit,student_duty_rank,student_work_age,student_email,student_address,student_tel_phone,student_memo_1,student_memo_2,create_time,create_user_id) " +
                "select "+dep_id+","+class_id+",t.c_1,t.c_2,t.c_3,t.c_4,student_sex.id,t.c_6,student_hj_address.id,t.c_8,student_hk_type.id,student_is_marray.id,student_nationality.id,student_political.id,t.c_13,student_type.id, " +
                "app_user_type.id,national_rank.id,up_national_rank.id,is_not_testing_theory.id,student_cultural.id,t.c_20,t.c_21,t.c_22,t.c_23,student_duty_rank.id,t.c_25,t.c_26,t.c_27,t.c_28,t.c_29,t.c_30, " +System.currentTimeMillis()/1000+","+getCurrentUserId()+" "+
                "from bk_project_student_import_temp t " +
                "left join sys_pa_code student_sex on student_sex.name=t.c_5 " +
                "left join sys_pa_code student_hj_address on student_hj_address.name=t.c_7 " +
                "left join sys_pa_code student_hk_type on student_hk_type.name=t.c_9 " +
                "left join sys_pa_code student_is_marray on student_is_marray.name=t.c_10 " +
                "left join sys_pa_code student_nationality on student_nationality.name=t.c_11 " +
                "left join sys_pa_code student_political on student_political.name=t.c_12 " +
                "left join sys_pa_code student_type on student_type.name=t.c_14 " +
                "left join sys_pa_code app_user_type on app_user_type.name=t.c_15 " +
                "left join sys_pa_code national_rank on national_rank.name=t.c_16 " +
                "left join sys_pa_code up_national_rank on up_national_rank.name=t.c_17 " +
                "left join sys_pa_code is_not_testing_theory on is_not_testing_theory.name=t.c_18 " +
                "left join sys_pa_code student_cultural on student_cultural.name=t.c_19 " +
                "left join sys_pa_code student_duty_rank on student_duty_rank.name=t.c_24 " +
                " where seq_id=?";
        int aa = Db.update(sql,seq_id);
        //清掉数据
        Db.update("delete from bk_project_student_import_temp  where seq_id=?",seq_id);

        rendJson_(1, "导入成功"+aa+"条记录");
    }

    public void impdata_student_update_info() {

        String seq_id = System.currentTimeMillis()+"";

        UploadFile uf = getFile("file_name", seq_id);

        String dep_id = getPara("dep_id");
        String class_id = getPara("class_id");

        Map<String, Object> map = PoiExt.ReadExcel(uf.getSaveDirectory() + "/" + uf.getFileName(),"student", "insert into bk_project_student_import_temp (seq_id,c_1,c_2,c_3,c_4,c_5,c_6,c_7,c_8,c_9,c_10,c_11,c_12,c_13,c_14,c_15,c_16,c_17,c_18,c_19,c_20,c_21,c_22,c_23,c_24,c_25,c_26,c_27,c_28,c_29,c_30) VALUES (" + seq_id + ",?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", 30);

        //去掉身份证为空的
        Db.update("delete from bk_project_student_import_temp  where c_4 is null and seq_id=?",seq_id);

        Record str_has_id_cart = Db.findFirst("select GROUP_CONCAT(t.c_4) student_id_cart from bk_project_student_import_temp t where t.c_4 not in (select s.student_id_cart from bk_student s where s.dep_id=? and s.class_id=? ) and t.seq_id=?",new Object[]{dep_id,class_id,seq_id});


        if(null!= str_has_id_cart.get("student_id_cart") && !str_has_id_cart.get("student_id_cart").toString().equals("")){
            rendJson_(0,"身份证不存在："+str_has_id_cart.get("student_id_cart"));
            return;
        }

        String sql = "update bk_student s,"+
                " bk_project_student_import_temp t " +
                "left join sys_pa_code student_sex on student_sex.name=t.c_5 " +
                "left join sys_pa_code student_hj_address on student_hj_address.name=t.c_7 " +
                "left join sys_pa_code student_hk_type on student_hk_type.name=t.c_9 " +
                "left join sys_pa_code student_is_marray on student_is_marray.name=t.c_10 " +
                "left join sys_pa_code student_nationality on student_nationality.name=t.c_11 " +
                "left join sys_pa_code student_political on student_political.name=t.c_12 " +
                "left join sys_pa_code student_type on student_type.name=t.c_14 " +
                "left join sys_pa_code app_user_type on app_user_type.name=t.c_15 " +
                "left join sys_pa_code national_rank on national_rank.name=t.c_16 " +
                "left join sys_pa_code up_national_rank on up_national_rank.name=t.c_17 " +
                "left join sys_pa_code is_not_testing_theory on is_not_testing_theory.name=t.c_18 " +
                "left join sys_pa_code student_cultural on student_cultural.name=t.c_19 " +
                "left join sys_pa_code student_duty_rank on student_duty_rank.name=t.c_24 " +
                " set s.student_name=t.c_1," +
                " s.student_sb_cart=t.c_2," +
                " s.student_sb_ffd=t.c_3," +
                " s.student_sex=student_sex.id," +
                " s.student_birthday=t.c_6," +
                " s.student_hj_address=student_hj_address.id," +
                " s.student_hj_address_detail=t.c_8," +
                " s.student_hk_type=student_hk_type.id,s.student_is_marray=student_is_marray.id," +
                " s.student_nationality=student_nationality.id," +
                " s.student_political=student_political.id," +
                " s.at_company=t.c_13," +
                " s.student_type=student_type.id," +
                " s.app_user_type=app_user_type.id," +
                " s.national_rank=national_rank.id," +
                " s.up_national_rank=up_national_rank.id," +
                " s.is_not_testing_theory=is_not_testing_theory.id," +
                " s.student_cultural=student_cultural.id," +
                " s.student_high_school_record=t.c_20," +
                " s.student_title=t.c_21," +
                " s.student_duty=t.c_22," +
                " s.student_age_limit=t.c_23," +
                " s.student_duty_rank=student_duty_rank.id," +
                " s.student_work_age=t.c_25," +
                " s.student_email=t.c_26," +
                " s.student_address=t.c_27," +
                " s.student_tel_phone=t.c_28," +
                " s.student_memo_1=t.c_29," +
                " s.student_memo_2=t.c_30," +
                " s.modify_time="+System.currentTimeMillis()/1000+"," +
                " s.modify_user_id=" +getCurrentUserId()+
                " where t.seq_id=? and t.c_4=s.student_id_cart ";
        int aa = Db.update(sql,seq_id);

        //清掉数据
        Db.update("delete from bk_project_student_import_temp  where seq_id=?",seq_id);

        rendJson_(1, "导入更新"+aa+"条记录");
    }

    public void get_pic(){

    }

    public void import_pic(){
        setAttr("id", getPara("id"));
    }

//    public void upload_pic(){
//        String seq_id = System.currentTimeMillis()+"";
//        UploadFile uf = getFile("file_name", seq_id);
//
//        String id = getPara("id");
//        BkStudentPic bsp = BkStudentPic.me.findById(id);
//        if(null == bsp){
//            bsp = new BkStudentPic();
//            bsp.set("id",id);
//            bsp.set("student_pic","upload/"+seq_id+"/"+uf.getFileName());
//            bsp.save();
//        }else{
//            bsp.set("student_pic","upload/"+seq_id+"/"+uf.getFileName());
//            bsp.update();
//        }
//
//        rendJson_(1, "上传成功");
//
//    }

    public void importImgStu(){
        String seq_id = System.currentTimeMillis()+"";
        UploadFile uf = getFile("file_name", seq_id);

        System.out.println("upload/" + seq_id + "/" + uf.getFileName());
//        rendJson_(1, "upload/"+seq_id+"/"+uf.getFileName());
        setAttr("success", 1);
        setAttr("obj", "upload/"+seq_id+"/"+uf.getFileName());
        render(new JsonRender().forIE());

    }

   

//    public void take_pic(){
//
//        String width = getPara("w");
//        String height = getPara("h");
//        String pix = getPara("pix");
//
//        String id = getPara("id");
//
//        int w = Integer.parseInt(width);
//        int h = Integer.parseInt(height);
//        String basePath = this.getRequest().getContextPath();
//        String savePath = this.getRequest().getRealPath("/");
//        String path = "upload/student_"+id+"/";
//        savePath +=path;
//        try {
//            BufferedImage bf = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
//            String[] rows = pix.split("\\|");
//            for (int i = 0; i < rows.length; i++) {
//                String[] col = rows[i].split(";");
//                for (int j = 0; j < col.length; j++) {
//                    int data = Integer.parseInt(col[j], 10);
//                    bf.setRGB(j, i, data);
//                }
//            }
//            File picPath = new File(savePath);
//            if (!picPath.exists()) {
//                picPath.mkdirs();
//            }
//            String fileName = UUID.randomUUID().toString() + ".jpg";
//            savePath += fileName;
//
//            ImageIO.write(bf, "jpg", new File(savePath));
//
//            path +=fileName;
//            BkStudentPic bsp = BkStudentPic.me.findById(id);
//            if(null == bsp){
//                bsp = new BkStudentPic();
//                bsp.set("id",id);
//                bsp.set("student_pic",path);
//                bsp.save();
//            }else{
//                bsp.set("student_pic",path);
//                bsp.update();
//            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        rendJson_(1, "上传成功",path);
//    }
    
    public void save_pic(){
    	
    	String id = StrUtil.getUUID();

        String width = getPara("w");
        String height = getPara("h");
        String pix = getPara("pix");

        int w = Integer.parseInt(width);
        int h = Integer.parseInt(height);
        String basePath = this.getRequest().getContextPath();
        String savePath = this.getRequest().getRealPath("/");
        String path = "upload/student_"+id+"/";
        savePath +=path;
        try {
            BufferedImage bf = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            String[] rows = pix.split("\\|");
            for (int i = 0; i < rows.length; i++) {
                String[] col = rows[i].split(";");
                for (int j = 0; j < col.length; j++) {
                    int data = Integer.parseInt(col[j], 10);
                    bf.setRGB(j, i, data);
                }
            }
            File picPath = new File(savePath);
            if (!picPath.exists()) {
                picPath.mkdirs();
            }
            String fileName = id + ".jpg";
            savePath += fileName;

            ImageIO.write(bf, "jpg", new File(savePath));

            path +=fileName;

        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(path);
        rendJson_(1, "上传成功",path);
    }

//    public void download_student(){
//        String id = getPara("id");
//        BkProject bp = BkProject.me.findById(id);
//
//        String[] columns = new String[] {
//                "id",
//                "dep_name",
//                "class_name",
//                "student_name",
//                "student_sb_cart",
//                "student_sb_ffd",
//                "student_id_cart",
//                "student_sex_name",
//                "student_birthday",
//                "student_hj_address",
//                "student_hj_address_detail",
//                "student_hk_type_name",
//                "student_is_marray_name",
//                "student_nationality_name",
//                "student_political_name",
//                "at_company",
//                "student_type_name",
//                "app_user_type_name",
//                "national_rank_name",
//                "up_national_rank_name",
//                "is_not_testing_theory_name",
//                "student_cultural_name",
//                "student_high_school_record",
//                "student_title",
//                "student_duty",
//                "student_age_limit",
//                "student_duty_rank_name",
//                "student_work_age",
//                "student_email",
//                "student_address",
//                "student_tel_phone",
//                "student_memo_1",
//                "student_memo_2",
//
//        };
//        String[] headers2 = new String[]{
//                "ID",
//                "学校",
//                "班级",
//                "学生姓名",
//                "社保卡号",
//                "社保卡发放地",
//                "身份证",
//                "性别",
//                "出生日期",
//                "户籍所在地",
//                "户籍地址",
//                "户口性质",
//                "婚姻状态",
//                "民簇",
//                "政治面貌",
//                "所在单位",
//                "人员类型",
//                "鉴定人员类别",
//                "国家职业资格等级",
//                "上一级职业资格级别",
//                "是否免考理论",
//                "文化程度",
//                "最高学历专业",
//                "职称",
//                "职务",
//                "职业年限",
//                "专业技术职务级别",
//                "工龄",
//                "电子邮箱",
//                "联系地址",
//                "联系电话",
//                "基础信息1",
//                "基础信息2"
//        };
//
//        Record user = getCurrentUser();
//
//        List<Object> param = new ArrayList<Object>();
//        StringBuffer where = new StringBuffer();
//        /** 添加查询字段条件*/
//        String sortName = this.getPara("sort");
//        String sortOrder = this.getPara("order", "desc");
//
//        String student_name = this.getPara("student_name", "");
//        String student_id_cart = this.getPara("student_id_cart", "");
//
//        String dep_id = this.getPara("dep_id", "");
//        String type = this.getPara("type", "");
//
//        where.append(" and FIND_IN_SET(s.dep_id,getDepChildList("+user.get("dep")+"))");
//
//        if(type.equals("1") && !"".equals(dep_id)){
//            where.append(" and FIND_IN_SET(s.dep_id,getDepChildList("+dep_id+"))");
//        }else if(type.equals("2") && !"".equals(dep_id)){
//            where.append(" and s.class_id="+dep_id);
//        }
//
//        if(!"".equals(student_name)){
//            where.append(" and s.student_name like '%"+student_name+"%'");
//        }
//        if(!"".equals(student_id_cart)){
//            where.append(" and s.student_id_cart like '%"+student_id_cart+"%'");
//        }
//
//        if(SysRole.me.is_teacher(getCurrentUserId().toString())){
//            where.append(" and exists (select 1 from bk_class bc where bc.id=s.class_id and bc.teacher_id="+getCurrentUserId()+") ");
//        }
//
//
//        String sql1 = "select s.id," +
//                "sys_department.dep_name," +
//                "bk_class.class_name class_name," +
//                "ifnull(s.student_name,'') student_name," +
//                "ifnull(s.student_sb_cart,'') student_sb_cart," +
//                "ifnull(s.student_sb_ffd,'') student_sb_ffd," +
//                "ifnull(s.student_id_cart,'') student_id_cart," +
//                "ifnull(student_sex.name,'') student_sex_name," +
//                "ifnull(s.student_birthday ,'') student_birthday," +
//                "ifnull(s.student_hj_address,'') student_hj_address," +
//                "ifnull(s.student_hj_address_detail,'') student_hj_address_detail," +
//                "ifnull(student_hk_type.name,'') student_hk_type_name, " +
//                "ifnull(student_is_marray.name,'') student_is_marray_name," +
//                "ifnull(student_nationality.name,'') student_nationality_name," +
//                "ifnull(student_political.name,'') student_political_name," +
//                "ifnull(s.at_company,'') at_company," +
//                "ifnull(student_type.name,'') student_type_name," +
//                "ifnull(app_user_type.name,'') app_user_type_name," +
//                "ifnull(national_rank.name,'') national_rank_name," +
//                "ifnull(up_national_rank.name,'') up_national_rank_name," +
//                "ifnull(is_not_testing_theory.name,'') is_not_testing_theory_name," +
//                "ifnull(student_cultural.name,'') student_cultural_name," +
//                "ifnull(s.student_high_school_record,'') student_high_school_record," +
//                "ifnull(s.student_title,'') student_title," +
//                "ifnull(s.student_duty,'') student_duty," +
//                "ifnull(s.student_age_limit,'') student_age_limit," +
//                "ifnull(student_duty_rank.name,'') student_duty_rank_name,"+
//                "ifnull(s.student_work_age,'') student_work_age," +
//                "ifnull(s.student_email,'') student_email," +
//                "ifnull(s.student_address,'') student_address," +
//                "ifnull(s.student_tel_phone,'') student_tel_phone," +
//                "ifnull(s.student_memo_1,'') student_memo_1," +
//                "ifnull(s.student_memo_2,'') student_memo_2 ";
//
//        String sql2 = " from bk_student s " +
//                "left join sys_department sys_department on s.dep_id=sys_department.id " +
//                "left join bk_class bk_class on s.class_id=bk_class.id " +
//                "left join sys_pa_code student_sex on s.student_sex=student_sex.id " +
//                "left join sys_pa_code student_hk_type on s.student_hk_type=student_hk_type.id " +
//                "left join sys_pa_code student_is_marray on s.student_is_marray=student_is_marray.id " +
//                "left join sys_pa_code student_type on s.student_type=student_type.id " +
//                "left join sys_pa_code app_user_type on s.app_user_type=app_user_type.id " +
//                "left join sys_pa_code national_rank on s.national_rank=national_rank.id " +
//                "left join sys_pa_code up_national_rank on s.up_national_rank=up_national_rank.id " +
//                "left join sys_pa_code is_not_testing_theory on s.is_not_testing_theory=is_not_testing_theory.id " +
//                "left join sys_pa_code student_cultural on s.student_cultural=student_cultural.id " +
//                "left join sys_pa_code student_nationality on s.student_nationality=student_nationality.id " +
//                "left join sys_pa_code student_political on s.student_political=student_political.id " +
//                "left join sys_pa_code student_duty_rank on s.student_duty_rank=student_duty_rank.id " +
//                " where 1=1 "+where.toString();
//
//        List<Record> data = Db.find(sql1+sql2);
//
//        String name = "学生信息表";
//
//        try {
//            name = new String(name.getBytes("GBK"),"ISO8859-1");
//        }catch (Exception e){
//
//        }
//
//        render(PoiRender.me(data).fileName(name + ".xls").columns(columns).headers(headers2));
//
//    }

    public void student_info(){
        render("student_info.html");
    }

   

    public void nation(){
    	String name = getPara("name","汉")+"族";
    	SysPaCode spc = SysPaCode.me.findFirst("select id from sys_pa_code where name like '%"+name+"'");
    	setAttr("success", 1);
        setAttr("obj", spc.get("id"));
        render(new JsonRender().forIE());
    }


}
